package com.yunwaikeji.gy_tool_library.utils.request;

import android.text.TextUtils;

import com.google.gson.Gson;

import java.io.File;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

public class GYMultipartBodyBuilder {
    private MediaType mediaType = MultipartBody.FORM;
    private String name = "file";
    private String fileName;
    private File file;

    public MultipartBody.Part buildPart() {
        RequestBody requestBody = RequestBody.create(mediaType, file);
        if (TextUtils.isEmpty(fileName) && file != null) {
            fileName = file.getName();
        }
        return MultipartBody.Part.createFormData(name, fileName, requestBody);
    }

    public MediaType getMediaType() {
        return mediaType;
    }

    public GYMultipartBodyBuilder setMediaType(MediaType mediaType) {
        this.mediaType = mediaType;
        return this;
    }

    public String getName() {
        return name;
    }

    public GYMultipartBodyBuilder setName(String name) {
        this.name = name;
        return this;
    }

    public String getFileName() {
        return fileName;
    }

    public GYMultipartBodyBuilder setFileName(String fileName) {
        this.fileName = fileName;
        return this;
    }

    public File getFile() {
        return file;
    }

    public GYMultipartBodyBuilder setFile(File file) {
        this.file = file;
        return this;
    }

    public GYMultipartBodyBuilder setFile(String file) {
        return setFile(new File(file));
    }
}
